<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<div id="sidebar" class="sidebar responsive">
    <script type="text/javascript">
        try { ace.settings.check('sidebar', 'fixed'); } catch (e) {}
        $(function() {
            $("#sidebar").css({
                "max-height" : $(window).height()-100,
                "overflow-y" : "auto",
                "overflow-x" : "hidden"
            });
        	$("#sidebar-collapse").click(function(){
        		 var w=$("#sidebar").css("width");
        		 var w1=parseInt(w.replace("px",""));
        		 var s=$("#sidebar").css("overflow-y");
        		 if("auto"==s && w1>100){
               		$("#sidebar").css({"overflow-y":"hidden"});
              	   }
               	 if(s=="hidden" && w1<100){
            		$("#sidebar").css({"overflow-y":"auto"});
          	   		}
             });
        });
        $(window).resize(function() {
            $("#sidebar").css({
                "max-height" : $(window).height()-100,
                "overflow-y" : "auto",
                "overflow-x" : "hidden"
            });
            $("#sidebar-collapse").click(function(){
       		 var w=$("#sidebar").css("width");
       		 var w1=parseInt(w.replace("px",""));
       		 var s=$("#sidebar").css("overflow-y");
       		 if("auto"==s && w1>100){
              		$("#sidebar").css({"overflow-y":"hidden"});
             	   }
              	 if(s=="hidden" && w1<100){
           		$("#sidebar").css({"overflow-y":"auto"});
         	   		}
            });
        });
    </script>
    <div class="sidebar-shortcuts" id="sidebar-shortcuts" style="display: none;">
        <div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
        
        </div>

        <div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
            <span class="btn btn-success"></span> 
            <span class="btn btn-info"></span> 
            <span class="btn btn-warning"></span> 
            <span class="btn btn-danger"></span>
        </div>
    </div>
    
    <ul id="sidebar_container" class="nav nav-list">
        <li id="sidebar_home" class="active" >
            <a href="#">
                <i class="menu-icon fa fa-home"></i><span class="menu-text">系统首页</span>
            </a>
            <b class="arrow"></b>
        </li>
    </ul>
    <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
        <i class="ace-icon fa fa-angle-double-left" 
            data-icon1="ace-icon fa fa-angle-double-left"
            data-icon2="ace-icon fa fa-angle-double-right">
        </i>
    </div>
    <script type="text/javascript">
    	var ctxPath = "${ctxPath}";
	    function toHtml(menu){
			var menuhtml;
			if(menu.url != null && menu.url != ""){
				menuhtml = "<li>"+
				"<a data-url='"+ctxPath+menu.url+"' data-addtabs='"+menu.code+"tab' data-title='"+menu.name+"' data-icon='"+menu.imgUrl+"' class='tmsp-pointer'>"+
				"<i class='menu-icon "+menu.imgUrl+"'></i>"+menu.name+"<b class='arrow'></b>"+
				"</a>"+
				"<b class='arrow'></b>"+
				"</li>";
			}else{
				menuhtml = "<li>"+
				"<a data-url='#' data-title='"+menu.name+"' data-icon='"+menu.imgUrl+"' class='dropdown-toggle tmsp-pointer'>"+
				"<i class='menu-icon "+menu.imgUrl+"'></i>"+
				"<span class='menu-text'>"+menu.name+"</span>"+
				"<b class='arrow fa fa-angle-down'></b>"+
				"</a>"+
				"<b class='arrow'></b>"+
				"<ul id='"+menu.code+"node' class='submenu nav-show'>"+
				"</ul>"+
				"</li>";
			}
			return menuhtml;
		}
	    
	    var url = ctxPath + '/menu/getMenuListByMap.do';
		$(function(){
			var param = {'user_id':shiroUser.user.id};
			$.ajax({
			    url:url,
			    type:'post',
			    data:param,
			    async : false,
			    success:function(resultData){
			    	var jsonObj=eval('('+resultData+')');
			    	for(var key in jsonObj){
			    		var menu=jsonObj[key];
			    		var html = toHtml(menu);
			        	var pCode = menu.pCode;
			            if(menu.levelNum != 1){
			            	$("#"+pCode+"node").append(html);
			            }else{
			            	$("#sidebar_container").append(html);
			            }
			    	}

			    }
			});
			$("[data-addtabs]").on("click", function() {
				addTabs({
					id : $(this).attr("data-addtabs"),
					title : $(this).attr('data-title'),
					url : $(this).attr('data-url'),
					icon : $(this).attr('data-icon'),
					close : true
				});
			});
		});
    </script>
    

</div>